jQuery(document).ready(function() {
	//创建JQGRID表格
	var grid = $("#table1").ligerGrid({
        columns: [
	           	 	{ display: '资源名称', name: 'name',type: 'string',width  : 300 },
	           		{ display: '操作类型', name: 'actions',type: 'string',width  : 60 },
	           		{ display: '权限类型', name: 'type',type: 'string',width  : 60 ,
	           		  render : function(rowdata, rowindex, value){
	           			if(value == 'com.byd.acegiext.domain.UrlPermission')
							return "页面链接";
	           			else if(value == 'com.byd.acegiext.domain.WebResourcePermission')
							return "页面资源";
	           			else if(value == 'com.byd.acegiext.domain.MethodPermission')
							return "业务方法";
	           			else return "实体资源";
	           		} },
	           	 	{ display: '权限描述', name: 'description',type: 'int',editor: { type: 'string'},width  : 200},
	           	 	{ display: '操作', width  : 150, render: function (rowdata, rowindex, value)
	                    {
	                        var h = "<a href='javascript:showPms(" + rowdata.id + ")'>分配角色</a> ";
	                        return h;
	                    }
					}
	            ],  usePager: true,pageSize:30,
                      url : sys_context+"/security/permiss/list.do",
                      width: '100%', height: '98%', checkbox: true,rownumbers:true,           
                      onDblClickRow : function (data, rowindex, rowobj){
                          edit(data);
                       }
                  });
	$("#pageloading").hide();
	
	
});
function showPms(id){
	var url = "/security/permiss/permissionEdit.do?rowId="+id;
	
	ShowIframeDialogMax("operate","权限角色管理",url,800,500);
}
//添加
function add(){
	var url = "/security/permiss/operate/add/0.do";
	
	ShowIframeDialog("operate","添加权限",url,650,300);
}
//编辑
function edit(data){
	var url = "/security/permiss/operate/edit/"+data.id+".do";
	ShowIframeDialog("operate","修改权限",url,650,300);
}

function del(){
	var manager = $("#table1").ligerGetGridManager(); 
	var rows = manager.getCheckedRows(); 
	
	if (rows.length==0){
		$.dialog.alert('Please select a record');
		return;
	}
    
    var ids = "";
	for(var i = 0;i < rows.length ;i ++) {
	 	if(i!=0){
	 		ids+=",";
	 	}
	 	//获得行数据
	 	ids += rows[i].id;					 	   
	}
	
	getDG().dialog({content: "请确定选择删除数据(Yes或者No)!",width: 250,lock: true,max: false,min: false,
		title:'Confirm Infor',
		button: [
		         {
		             name: 'Yes',
		             callback: function(){
			            $.ajax({
			           	      url: sys_context+"/security/permiss/delete.do",
			           	      global: false,
			           	      type: "POST",
			           	      dataType: "json",
			           	      data: ({ids : ids}),		     
			           	      success: function(msg){	
			           	    	manager.removeRange(rows);
			           	    	  $.dialog.alert(msg.infor);  		    	
			           	      }
			           	   }
			           	);
		             }
		         },
		         {
		        	   name: 'No',
			           focus: true
		         }             
		     ]
	}).zindex();
	
	
}